package com.life.xxx.api;

import com.life.xxx.util.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

import com.life.xxx.entity.Shop;
import com.life.xxx.service.ShopService;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author csl
* @since 2025-08-07
*/
@RestController
@RequestMapping("/shop")
public class ShopApi {

    @Autowired
    private ShopService shopService;

    /**
    * 获取所有数据
    */
    @GetMapping
    public List<Shop> getAll() {
        return shopService.list();
    }

    /**
    * 根据 ID 获取数据
    */
    @GetMapping("/{id}")
    public Shop getById(@PathVariable("id") Long id) {
        return shopService.getById(id);
    }

    /**
    * 分页查询
    */
    @GetMapping("/page")
    public Page<Shop> getPage(Page<Shop> page,Shop shop) {
        return shopService.queryByPage(page,shop);
    }

    /**
    * 创建数据
    */
    @PostMapping
    public boolean create(@RequestBody Shop shop) {
        return shopService.save(shop);
    }

    /**
    * 更新数据
    */
    @PutMapping
    public boolean update(@RequestBody Shop shop) {
        return shopService.updateById(shop);
    }

    /**
    * 删除数据
    */
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return shopService.removeById(id);
    }
}